package com.shopping.mall.core.module.order.service.impl;

import com.shopping.mall.auth.utils.UserUtils;
import com.shopping.mall.core.module.user.entity.User;
import com.shopping.mall.core.util.MailUtils;
import com.shopping.mall.core.module.order.entity.Order;
import com.shopping.mall.core.module.order.service.MailService;
import com.shopping.mall.core.module.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;

@Service
public class MailServiceImpl implements MailService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private MailUtils mailUtils;

    @Async
    @Override
    public void payOrder(Order oldOrder) {
        System.out.println("这里在发邮件");
        User user=userMapper.selectById(oldOrder.getUserId());
        mailUtils.sendPayedMail(user.getMail(),oldOrder.getOrderNumber(),new Timestamp(new Date().getTime()));
    }

//    @Async
    @Override
    public void sendOrder(Order order) {
        User user=userMapper.selectById(order.getUserId());
        mailUtils.sendDeliverMail(user.getMail(),order.getOrderNumber(),new Timestamp(new Date().getTime()));
    }

    @Async
    @Override
    public void finishOrder(Order order) {
        User user=userMapper.selectById(order.getUserId());
        mailUtils.sendClickMail(user.getMail(),order.getOrderNumber(),new Timestamp(new Date().getTime()));
    }

    @Async
    @Override
    public void autoFinishOrder(Order order) {
        User user=userMapper.selectById(order.getUserId());
        mailUtils.send30DayMail(user.getMail(),order.getOrderNumber(),new Timestamp(new Date().getTime()));
    }

}
